- 
                Notifications
    You must be signed in to change notification settings 
- Fork 49.7k
          Avoid acccessing React internals from use-sync-external-store/shim
          #29868
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    Avoid acccessing React internals from use-sync-external-store/shim
  
  #29868
              Conversation
Prior to this change, the build process would replace `console.error` with an `error` call that then again would call `printWarning`, which accesses `React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` in current stable versions (see https://unpkg.com/browse/[email protected]/cjs/use-sync-external-store-shim.development.js) and `React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE` in future versions (see https://unpkg.com/browse/[email protected]/cjs/use-sync-external-store-shim.development.js). This might cause builds to fail. With this change, that replacement is avoided and a normal `console.error` call is made instead.
| @phryneas is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add a test to packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js for the warning by extracting the necessary code from https://codesandbox.io/p/sandbox/react-19-uses-old-react-vl547c?file=%2Fsrc%2Findex.js%3A11%2C43
| I believe just changing the existing test to "should never include a stack trace" should test for this sufficiently - I'm not sure how to run the tests with different flags, though. | 
| The latest updates on your projects. Learn more about Vercel for Git ↗︎ 
 | 
        
          
                packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js
              
                Outdated
          
            Show resolved
            Hide resolved
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
| Thank you for walking me through this! | 
…29868) Co-authored-by: eps1lon <[email protected]> DiffTrain build for [50e89ec](50e89ec)
Fixes #29854
Summary
Prior to this change, the build process or
use-sync-external-storewould replaceconsole.errorwithan
errorcall that then again would callprintWarning, which accessesReact.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIREDin current stableversions (see https://unpkg.com/browse/[email protected]/cjs/use-sync-external-store-shim.development.js)
and
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADEin future versions(see https://unpkg.com/browse/[email protected]/cjs/use-sync-external-store-shim.development.js).
This might cause builds to fail, as there would be no version of the package that is compatible with both React 18 and 19.
With this change, that replacement is avoided and a normal
console.errorcall is made instead.
How did you test this change?
I verified by locally building this locally with
yarn build use-sync-external-storeand looking at the build output atbuild/oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.